<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ page import="beans.Vehicle" %>
<%@ page import="beans.Drivers" %>
<%@ page import="java.util.List" %>
<%@ page import="java.util.Collections" %>
<%
    // 检查session是否存在
    if(session.getAttribute("username") == null) {
        response.sendRedirect(request.getContextPath() + "/login.jsp");
        return;
    }
    String username = (String)session.getAttribute("username");
    String role = (String)session.getAttribute("role");
    Object user = session.getAttribute("user");

    // 确保列表不为null
    List<Vehicle> vehicles = (List<Vehicle>) request.getAttribute("vehicles");
    List<Drivers> drivers = (List<Drivers>) request.getAttribute("drivers");

    if (vehicles == null) {
        vehicles = Collections.emptyList();
        System.out.println("Vehicles list is null in JSP");
    }
    if (drivers == null) {
        drivers = Collections.emptyList();
        System.out.println("Drivers list is null in JSP");
    }
%>
<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <title>维修订单 - 公司用车管理系统</title>
    <!-- 添加Font Awesome图标库 -->
    <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/5.15.4/css/all.min.css">
    <style>
        /* 全局样式 */
        body {
            margin: 0;
            padding: 0;
            font-family: "Microsoft YaHei", Arial, sans-serif;
            background: #f6f6f6;
        }

        /* 头部样式 */
        .header {
            background: #183a8a;
            color: #fff;
            font-size: 2rem;
            font-weight: bold;
            padding: 10px 0 10px 10px;
            letter-spacing: 2px;
            display: flex;
            align-items: center;
            justify-content: space-between;
        }
        .header-right {
            display: flex;
            align-items: center;
            margin-right: 30px;
            font-size: 1rem;
        }
        .user-icon {
            width: 40px;
            height: 40px;
            border-radius: 50%;
            background: #fff;
            color: #183a8a;
            display: flex;
            align-items: center;
            justify-content: center;
            font-size: 2rem;
            margin-right: 10px;
        }
        .user-info {
            margin-right: 20px;
            color: #fff;
        }
        .bell-icon {
            font-size: 1.3rem;
            margin-right: 20px;
            color: #fff;
        }
        .logout {
            color: #fff;
            text-decoration: none;
            margin-left: 10px;
            font-size: 1rem;
            padding: 8px 15px;
            border-radius: 4px;
            background: rgba(255,255,255,0.1);
            transition: background 0.3s ease;
        }
        .logout:hover {
            background: rgba(255,255,255,0.2);
        }

        /* 主体容器 */
        .container {
            display: flex;
            height: calc(100vh - 56px);
        }

        /* 侧边栏样式 */
        .sidebar {
            width: 220px;
            background: #183a8a;
            display: flex;
            flex-direction: column;
            padding-top: 10px;
            box-shadow: 2px 0 8px rgba(24,58,138,0.05);
        }
        .menu-item {
            color: #fff;
            padding: 18px 0 18px 32px;
            font-size: 1.15rem;
            cursor: pointer;
            border-left: 5px solid transparent;
            transition: background 0.2s, border 0.2s;
            text-decoration: none;
            display: flex;
            align-items: center;
        }
        .menu-item i {
            margin-right: 10px;
            width: 20px;
            text-align: center;
        }
        .menu-item.active, .menu-item:hover {
            background: #2450a7;
            border-left: 5px solid #fff;
            font-weight: bold;
            box-shadow: 0 4px 8px rgba(24,58,138,0.10);
        }

        /* 主内容区样式 */
        .main-content {
            flex: 1;
            background: #fff;
            border: 2px solid #3ba0e9;
            border-left: none;
            padding: 20px;
            overflow-y: auto;
        }
        .section-title {
            font-size: 20px;
            font-weight: bold;
            margin-bottom: 18px;
        }
        .form-section {
            background: #fff;
            border-radius: 4px;
            padding: 24px 24px 12px 24px;
            box-shadow: 0 2px 8px rgba(0,0,0,0.04);
            margin-bottom: 20px;
        }
        .form-row {
            display: flex;
            margin-bottom: 16px;
        }
        .form-row label {
            width: 120px;
            text-align: right;
            line-height: 32px;
            margin-right: 10px;
            font-size: 16px;
        }
        .form-row input[type="text"],
        .form-row select,
        .form-row input[type="date"] {
            flex: 1;
            padding: 6px 10px;
            font-size: 16px;
            border: 1px solid #ccc;
            border-radius: 3px;
            outline: none;
        }
        .form-row textarea {
            flex: 1;
            padding: 6px 10px;
            font-size: 16px;
            border: 1px solid #ccc;
            border-radius: 3px;
            outline: none;
            resize: vertical;
            min-height: 60px;
        }
        .form-row .file-label {
            display: inline-block;
            padding: 6px 16px;
            background: #e0e0e0;
            border-radius: 3px;
            cursor: pointer;
            margin-right: 10px;
        }
        .form-row input[type="file"] {
            display: none;
        }
        .form-row .file-name {
            color: #888;
            font-size: 14px;
        }
        .form-row .btn {
            background: #2196f3;
            color: #fff;
            border: none;
            border-radius: 3px;
            padding: 8px 24px;
            font-size: 16px;
            cursor: pointer;
            margin-top: 10px;
        }
        .history-section {
            background: #fff;
            border-radius: 4px;
            padding: 16px 24px;
            box-shadow: 0 2px 8px rgba(0,0,0,0.04);
            margin-bottom: 20px;
        }
        .history-table {
            width: 100%;
            border-collapse: collapse;
            margin-top: 10px;
        }
        .history-table th, .history-table td {
            border: 1px solid #e0e0e0;
            padding: 8px 12px;
            text-align: center;
            font-size: 15px;
        }
        .history-table th {
            background: #f5f7fa;
            font-weight: bold;
        }
        .history-table td a {
            color: #1976d2;
            text-decoration: underline;
            cursor: pointer;
        }
        @media (max-width: 900px) {
            .sidebar {
                width: 120px;
            }
            .menu-item {
                padding-left: 15px;
                font-size: 1rem;
            }
            .main-content { padding: 10px; }
            .btn {
                padding: 10px 20px;
                font-size: 16px;
                background-color: #4CAF50;
                color: white;
                border: none;
                border-radius: 5px;
                cursor: pointer;
            }
            .btn:hover {
                background-color: #45a049;
            }
        }
    </style>
    <script>
        function showSuccessMessage() {
            alert("已成功提交维修单");
        }
    </script>
</head>
<body>
<div class="header">
    <div>欢迎登录公司用车管理系统（司机）</div>
    <div class="header-right">
        <div class="user-icon">👤</div>
        <div class="user-info">工号：<%=username%></div>
        <div class="bell-icon">🔔</div>
        <a href="<%=request.getContextPath()%>/login.jsp" class="logout">退出登录</a>
    </div>
</div>

<div class="container">
    <div class="sidebar">
        <a class="menu-item" href="DriversServlet?action=1234">
            <i class="fas fa-home"></i> 系统首页
        </a>
        <a class="menu-item" href="DriversServlet?action=a">
            <i class="fas fa-user"></i> 个人中心
        </a>
        <%--    <a class="menu-item" href="DriversServlet?action=b">--%>
        <%--      <i class="fas fa-tasks"></i> 我的待办--%>
        <%--    </a>--%>
        <a class="menu-item" href="DriversServlet?action=c">
            <i class="fas fa-list"></i> 全部订单
        </a>
        <a class="menu-item active" href="DriversServlet?action=d">
            <i class="fas fa-tools"></i> 维修单提交
        </a>
        <a class="menu-item" href="DriversServlet?action=e">
            <i class="fas fa-money-bill-wave"></i> 用车费用提交
        </a>
    </div>

    <div class="main-content">
        <div class="form-section">

            <div class="section-title">维修单提交</div>
            <form id="repairForm" action="MaintenanceServlet?action=submit" method="post" enctype="multipart/form-data">
                <div class="form-row">
                    <label>车辆ID</label>
                    <input type="text" name="vehicleID" required>
                    <label style="margin-left:40px;">维修日期</label>
                    <input type="date" name="maintenanceTime" style="max-width:200px;" required>
                </div>
                <div class="form-row">
                    <label>司机ID</label>
                    <input type="text" name="driverID" required>
                    <label style="margin-left:40px;">维修金额(元)</label>
                    <input type="text" name="cost" style="max-width:200px;" required>
                </div>
                <div class="form-row">
                    <label>维修描述</label>
                    <textarea name="purpose" placeholder="请填写维修内容、原因等" required></textarea>
                </div>
                <div class="form-row">
                    <label>上传凭证</label>
                    <label class="file-label">
                        选择文件
                        <input type="file" id="fileInput" name="receipt" onchange="showFileName(event)" required>
                    </label>
                    <span class="file-name" id="fileName">未选择任何文件</span>
                </div>
                <div class="form-row" style="justify-content: flex-start;">
                    <button type="submit" class="btn" onclick="showSuccessMessage()">提交维修单</button>
                </div>
            </form>
        </div>
        <div class="history-section">
            <div class="section-title" style="font-size:17px;">历史维修记录</div>
            <table class="history-table">
                <thead>
                <tr>
                    <th>维修单号</th>
                    <th>车牌号</th>
                    <th>维修描述</th>
                    <th>维修金额</th>
                    <th>状态</th>
                    <th>操作</th>
                </tr>
                </thead>
                <tbody>
                <tr>
                    <td>REP20235001</td>
                    <td>粤A12345</td>
                    <td>发动机维修</td>
                    <td>￥800.00</td>
                    <td>已完成</td>
                    <td><a href="#">查看</a></td>
                </tr>
                <tr>
                    <td>REP20235002</td>
                    <td>粤B67890</td>
                    <td>轮胎更换</td>
                    <td>￥300.00</td>
                    <td>审核中</td>
                    <td><a href="#">查看</a></td>
                </tr>
                </tbody>
            </table>
        </div>
    </div>
</div>
<script>
    function showFileName(event) {
        const fileInput = event.target;
        const fileName = fileInput.files.length > 0 ? fileInput.files[0].name : "未选择任何文件";
        document.getElementById('fileName').textContent = fileName;
    }

    // 设置默认日期为今天
    document.addEventListener('DOMContentLoaded', function() {
        const today = new Date().toISOString().split('T')[0];
        document.querySelector('input[name="maintenanceTime"]').value = today;
    });
</script>
</body>
</html>